package com.xwj.back.controller;

import com.xwj.back.pojo.OrderPay;
import com.xwj.back.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/order/getAll/")
    public List<OrderPay> getOrders(@RequestParam Map<String,String> data){
        String username = data.get("username");
        String role = data.get("role");
        return orderService.getOrders(username,role);
    }

    @PostMapping("/order/add/")
    public Map<String,String> addOrder(@RequestBody Map<String,String> data){
        Map<String, String> map = new HashMap<>();
        map.put("message", orderService.addOrder(data));
        return map;
    }

    @PostMapping("/order/delete/")
    public Map<String,String> deleteOrder(@RequestBody Map<String,String> data){
        Map<String, String> map = new HashMap<>();
        map.put("message", orderService.deleteOrder(data));
        return map;
    }

    @PostMapping("/order/update/")
    public Map<String,String> updateOrder(@RequestBody Map<String,String> data){
        Map<String, String> map = new HashMap<>();
        map.put("message", orderService.updateOrder(data));
        return map;
    }

    @GetMapping("/order/getByStatus/")
    public List<OrderPay> getOrdersByStatus(@RequestParam boolean status){
        return orderService.getOrdersByStatus(status);
    }

    @PostMapping("/order/import/excel/")
    public Map<String,String> importExcel(MultipartFile file) throws IOException {
        return orderService.ImportExcel(file);
    }
}
